<template>
  <div>879077</div>
</template>

<script>
// import axios from 'axios'
export default {
  data() {
    return {};
  },
  created() {
    const workerJSString = `
    // 接收主线程发来的的数据
    onmessage = ({data})=>{
      // 向主线程发送data
      console.log(\`接收到主线程发来的数据: \${data}\`);
      // var xhr = new XMLHttpRequest()
      fetch('http://localhost:8080/api/datasources')
      postMessage();
    }
    `;

    const workerBlob = new Blob([workerJSString], {
      type: "text/javascript",
    });
    const url = URL.createObjectURL(workerBlob);
    const myWorker = new Worker(url);

    // 监听子线程发来的 数据
    myWorker.addEventListener("message", ({ data }) => {
      console.log(data); // 9
    });

    setTimeout(function () {
      // 向子进程的数据
      myWorker.postMessage({ items: [12,'34', new Date() ]});
    }, 2000);
  },
  methods: {},
};
</script>